<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog">
        <el-form :model="addPanFilesForm" ref="addPanFilesRef" :rules="addPanFilesrules">
                        <el-form-item label="文件名称" :label-width="formLabelWidth"
                                      prop="name">
                            <el-input
                                    v-model="addPanFilesForm.name"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件名称"
                            ></el-input>
                        </el-form-item>
                        <!-- <el-form-item label="文件大小" :label-width="formLabelWidth"
                                      prop="fileSize" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.fileSize"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件大小"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="文件夹ID" :label-width="formLabelWidth"
                                      prop="folderId" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.folderId"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件夹ID"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="校区" :label-width="formLabelWidth"
                                      prop="campus" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.campus"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写校区"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="人员编号" :label-width="formLabelWidth"
                                      prop="teacherNumber">
                            <el-input
                                    v-model="addPanFilesForm.teacherNumber"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写人员编号"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="更新时间" :label-width="formLabelWidth"
                                      prop="updateTime" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.updateTime"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写更新时间"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="文件md5" :label-width="formLabelWidth"
                                      prop="md5">
                            <el-input
                                    v-model="addPanFilesForm.md5"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件md5"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="上传状态" :label-width="formLabelWidth"
                                      prop="status" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.status"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写上传状态"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="文件访问路径" :label-width="formLabelWidth"
                                      prop="url">
                            <el-input
                                    v-model="addPanFilesForm.url"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件访问路径"
                            ></el-input>
                        </el-form-item> -->
                        <!-- <el-form-item label="文件类型" :label-width="formLabelWidth"
                                      prop="type" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.type"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写文件类型"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="是否在回收站" :label-width="formLabelWidth"
                                      prop="isEffect" v-if="addPanFilesForm.id">
                            <el-input
                                    v-model="addPanFilesForm.isEffect"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写是否在回收站"
                            ></el-input>
                        </el-form-item> -->
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="save()">保存</el-button>
      </span>
        </template>
    </el-dialog>
</template>

<script>
    import {ref} from "vue";
    import {httpService} from "@/utils/httpService";
    import {ElMessage, ElForm} from "element-plus";
    import {vxRule} from "@/utils/validator";

    export default {
        name: "AddPanFiles",
        components: {ElForm, ElMessage},
        data() {
            return {
                dialogFormVisible: ref(false),
                formLabelWidth: "120px",
                title: "",
                personnelType: "",
                addPanFilesForm: {
                    name: "",
                    fileSize: "",
                    folderId: "",
                    campus: "",
                    teacherNumber: "",
                    updateTime: "",
                    md5: "",
                    status: "",
                    url: "",
                    type: "",
                    isEffect: "",
                },
                // 校验规则
                addPanFilesrules: {
                    name: vxRule(true, null, "blur"),
                    teacherNumber: vxRule(true, null, "blur"),
                    md5: vxRule(true, null, "blur"),
                    url: vxRule(true, null, "blur"),
                },
            };
        },
        methods: {
            closeDialog() {
                this.clear();
            },
            cancel() {
                this.dialogFormVisible = false;
                this.clear();
            },
            getPanFilesById(id) {
                httpService("/javaApi/panFiles/queryById", {id: id}, "get").then(
                    (data) => {
                        this.addPanFilesForm = data;
                    }
                );
            },
            clear() {
                this.dialogFormVisible = false;
                //清空form
                    this.addPanFilesForm.id = "";
                    this.addPanFilesForm.name = "";
                    this.addPanFilesForm.fileSize = "";
                    this.addPanFilesForm.folderId = "";
                    this.addPanFilesForm.campus = "";
                    this.addPanFilesForm.teacherNumber = "";
                    this.addPanFilesForm.updateTime = "";
                    this.addPanFilesForm.md5 = "";
                    this.addPanFilesForm.status = "";
                    this.addPanFilesForm.url = "";
                    this.addPanFilesForm.type = "";
                    this.addPanFilesForm.isEffect = "";
            },
            save() {
                this.$refs.addPanFilesRef.validate((valid) => {
                    if (valid) {
                        let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                        params.append("name", this.addPanFilesForm.name);
                        // params.append("fileSize", this.addPanFilesForm.fileSize);
                        // params.append("folderId", this.addPanFilesForm.folderId);
                        // params.append("campus", this.addPanFilesForm.campus);
                        // params.append("teacherNumber", this.addPanFilesForm.teacherNumber);
                        // params.append("updateTime", this.addPanFilesForm.updateTime);
                        // params.append("md5", this.addPanFilesForm.md5);
                        // params.append("status", this.addPanFilesForm.status);
                        // params.append("url", this.addPanFilesForm.url);
                        // params.append("type", this.addPanFilesForm.type);
                        // params.append("isEffect", this.addPanFilesForm.isEffect);
                        if (this.addPanFilesForm.id) {
                            params.append("id", this.addPanFilesForm.id);
                            httpService("/javaApi/panFiles/edit", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("修改成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getPanFilesList();
                                    } else {
                                        ElMessage.error("修改失败");
                                    }
                                }
                            );
                        } else {
                            httpService("/javaApi/panFiles/add", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("添加成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getPanFilesList();
                                    } else {
                                        ElMessage.error("添加失败");
                                    }
                                }
                            );
                        }
                    } else {
                        return false;
                    }
                });
            },
        },
    };
</script>
<style>
</style>